From: Florian Müllner Date: Wed, 25 Feb 2015 22:23:49 +0000 (+0100) Subject: util: Add createTimeLabel() X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~1579 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=8f424e7d96c823552f30cde2bd4471fedb42031e;p=gnome-shell.git util: Add createTimeLabel() On locales that support it, time formats should follow the 12-hour/24-hour preference, which implies that they should be updated when the setting changes. So add another utility method which creates a label for a specific time and keeps it in sync with the format setting. https://bugzilla.gnome.org/show_bug.cgi?id=745111 --- diff --git a/js/misc/util.js b/js/misc/util.js index c938fdcbd..748c7b7d5 100644 --- a/js/misc/util.js +++ b/js/misc/util.js @@ -246,6 +246,20 @@ function formatTime(time, params) { return date.format(Shell.util_translate_time_string(format)); } +function createTimeLabel(date, params) { + if (_desktopSettings == null) + _desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' }); + + let label = new St.Label({ text: formatTime(date, params) }); + let id = _desktopSettings.connect('changed::clock-format', function() { + label.text = formatTime(date, params); + }); + label.connect('destroy', function() { + _desktopSettings.disconnect(id); + }); + return label; +} + // lowerBound: // @array: an array or array-like object, already sorted // according to @cmp